import { _decorator, Component, Node, v3 } from 'cc';
import { HomeView } from './View/HomeView';
import { ResultView } from './View/ResultView';
import { EventMsg, ResultEnum } from './DataCenter/GlobalContext';
import ObjPool from './DataCenter/ObjPool';
import EventManager from './Util/EventManager';
import { BattleView } from './View/BattleView';
import { RoleView } from './View/RoleView';
const { ccclass, property } = _decorator;

@ccclass('GameController')
export class GameController extends Component {
    @property(Node)
    HomeView: Node = null;
    @property(Node)
    BattleView: Node = null;
    @property(Node)
    ResultView: Node = null;
    @property(Node)
    RoleView: Node = null;

    static _instance: GameController = null;
    static get inst(){
        return GameController._instance;
    }

    onLoad(): void {
        GameController._instance = this;
    }

    start(): void {
        EventManager.getInst().On(EventMsg.INIT_ROLR_COMPLE, this.showHomeView, this);
        ObjPool.inst.initRoles();
    }

    showHomeView(){
        this.BattleView.active = false;
        this.ResultView.active = false;
        this.RoleView.active = false;
        this.HomeView.active = true;

        let homeView: HomeView = this.HomeView.getComponent(HomeView);
        homeView.Show();
    }

    showBattleView(){
        this.BattleView.active = true;
        this.ResultView.active = false;
        this.HomeView.active = false;
        this.RoleView.active = false;

        let battleView: BattleView = this.BattleView.getComponent(BattleView);
        battleView.Show();
    }

    showResultView(resultEnum: ResultEnum){
        this.RoleView.active = false;
        this.ResultView.active = true;

        let resultView: ResultView = this.ResultView.getComponent(ResultView);
        resultView.Show(resultEnum);
    }

    showRoleView(roleId: string){
        this.RoleView.active = true;

        let roleView: RoleView = this.RoleView.getComponent(RoleView);
        roleView.Show(roleId);
    }
}


